package com.example.yuanboot.common.config.mybatis;

import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 基于mybatis的数据拦截
 *
 * @author qingyan 2021-07-21
 */
//@Configuration
@AutoConfigureAfter(PaginationInnerInterceptor.class)
public class MybatisPermissionConfig{

    @Autowired
    private List<SqlSessionFactory> sqlSessionFactoryList;

    @PostConstruct
    public void addMyInterceptor() {
        DataPermissionInterceptor e = new DataPermissionInterceptor();
        e.setPropertes(new UserInfoInterceptor(),"submit_user_id");
        for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
            sqlSessionFactory.getConfiguration().addInterceptor(e);
        }
    }
}
